package org.testing;

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;

public class LoginSystem {

	public static User userLogin(String login) throws FileNotFoundException {
		Scanner file_scan = new Scanner(new FileReader("users"));
		while(file_scan.hasNext()){	
			String f_out=file_scan.nextLine();
			String[] buf = f_out.split("/");
			if (buf[0].equals(login)) {
				if (buf[1].equals("admin")) {
					return new User(login, true);
				} else {
					return new User(login, false);
				}
			}	
		}
		return null;
	}

	public static void singUp(String login) throws IOException {
		FileWriter wr = new FileWriter("users",true);
		wr.write(login);
		wr.write("/");
		wr.write("student");
		wr.write("\r\n");
		wr.close(); 	
	}

}
